<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Goodlist;
use App\Model\Goods;

class GoodsListController extends CommonController
{
    /*货品管理*/
    public function lists($id, Request $request)
    {
        if ($request->isMethod('post')) {
            $Goodlist = new Goodlist;
            $Goodlist->lists = $request->lists;
            $Goodlist->stock = $request->stock;
            $Goodlist->goods_id = $id;
            $Goodlist->save();
            return redirect('/admin/goodslist/' . $id)->with('status', '操作成功');
        }
        $goods = Goods::find($id);
        $lists = Goodlist::where('goods_id', $id)->get();
        return view('admin.goodslist.lists', compact('goods','lists'));
    }

    /*删除货品*/
    public function goodslistdel($id)
    {
        $list = Goodlist::find($id);
        $list->delete();
        return redirect('/admin/goodslist/' . $list['goods_id'])->with('status', '操作成功');
    }

}
